// pages/rotateText/rotateText.js  
const sendMessage = require('../home/home.js')
var thatAll;
Page({  
  data: {  
     img:["/images/up.png","/images/right.png","/images/bottom.png","/images/left.png"],
     list:[],
     selected:"",
     time:0
  },  
  onLoad(){
    var that = this;
    var that = this;
    thatAll = that;
    var list = [];
    for(var i=0;i<25;i++){
      let random = Math.floor(Math.random() * 4);
      var selected = false;
      if(i == 0){
        selected = true;
      }
      list.push({"random":random,"selected":selected,"num":i});
    }
    that.setData({
      list:list,
      selected:0
    });
    //this.start();
  },
  onShow(){
  },
  getRings(){
    this.canvasRing = this.selectComponent("#canvas");
    this.canvasRing.drawCanvasRing()
  },
  /**点击 */
  dianji(e){
    var that = this;
    var type = e.target.dataset.type;
    var selected = that.data.selected;
    var list = that.data.list;
    if(type == list[selected].random){
      //随机
      // let index = Math.floor(Math.random() * 25);
      // list[selected].selected = false;
      // list[index].selected = true;
      // that.setData({
      //   list:list,
      //   selected:index
      // })
      //顺序
      list[selected].selected = false;
      if(selected+1 < list.length){
        selected += 1;
        list[selected].selected = true;
      }else{
        selected = 0;
        list[0].selected = true;
      }
      console.log("正确 "+"selected："+selected);
      sendMessage.BLEDataSend("aa55a55a210100cc66c66c");
      that.setData({
        list:list,
        selected:selected
      });
      that.end();
      that.start();
    }else{
      if(type == 4){
        console.log("看不清 "+"selected："+selected);
        list[selected].selected = false;
        if(selected+1 < list.length){
          selected += 1;
          list[selected].selected = true;
        }else{
          selected = 0;
          list[0].selected = true;
        }
        that.setData({
          list:list,
          selected:selected
        });
        that.end();
        that.start();
      }else{
        wx.showToast({
          title: "错误",
          icon: "none",
          mask: false, 
          duration:1000 
        });
      }
    }
  },
  start(){
    var that = this;
    var time =  that.data.time;
    // var timer = setInterval(()=>{
    //      time += 0.01;
    //      that.setData({
    //       time:time.toFixed(2),
    //      })
    // },10);
    // that.setData({
    //   timer:timer,
    // });
  },
  end(){
    var that = this;
    console.log("结束：");
    that.setData({
      time:0,
    });
   // clearInterval(that.data.timer);
  }
});
function test(time){
    thatAll.setData({
      time:time
    })
}
module.exports = {
  test:test,
}